/*
 * Copyright 2008-2009 Daniel Cachapa <cachapa@gmail.com>
 * 
 * This program is distributed under the terms of the GNU General Public Licence Version 3
 * The licence can be read in its entirety in the LICENSE.txt file accompaning this source code,
 * or at: http://www.gnu.org/copyleft/gpl.html
 * 
 * This file is part of WeightWatch.
 *
 * WeightWatch is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, version 3 of the License.
 *
 * WeightWatch is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with the WeightWatch source code. If not, see
 * <http://www.gnu.org/licenses/>.
 */

package net.cachapa.weightwatch;

import net.cachapa.weightwatch.util.L;

public class Bmi {
	// These values are the minimum to reach each level
	public final static double STARVATION = 0;
	public final static double SEVERELY_UNDERWEIGHT = 16;
	public final static double UNDERWEIGHT = 17;
	public final static double NORMAL = 18.5;
	public final static double OVERWEIGHT =	25;
	public final static double OBESE_I = 30;
	public final static double OBESE_II = 35;
	public final static double OBESE_III = 40;
	
	public static double calculateBMI(double weight, double height, boolean metricValues) {
		if (metricValues) {
			return weight / (height * height);
		}
		
		else {
			return weight * 4.88 / (height * height);
		}
	}
	
	public static double getWeight(double bmi, double height, boolean metricValues) {
		if (metricValues) {
			return bmi * height * height;
		}
		
		else {
			return bmi * height * height / 4.88;
		}
	}
	
	public static String getLevelName(double bmi) {
		if (bmi < SEVERELY_UNDERWEIGHT)
			return L.l("Starvation");
		if (bmi < UNDERWEIGHT)
			return L.l("Severely underweight");
		if (bmi < NORMAL)
			return L.l("Underweight");
		if (bmi < OVERWEIGHT)
			return L.l("Normal");
		if (bmi < OBESE_I)
			return L.l("Overweight");
		if (bmi < OBESE_II)
			return L.l("Obese class I");
		if (bmi < OBESE_III)
			return L.l("Obese class II");
		return L.l("Obese class III");
	}
	
	public static double getAverageWeight(double height, boolean metricValues) {
		double averageBmi = ((OVERWEIGHT - NORMAL) / 2) + NORMAL;
		return getWeight(averageBmi, height, metricValues);
	}
}
